package com.me.blood.frag;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.me.blood.R;
import com.me.blood.databinding.DlgSugarBinding;

import java.util.ArrayList;
import java.util.List;

public class AddTypeDlg extends FullScreenDlg {

    DlgSugarBinding binding;
    List<TextView> list = new ArrayList<>();
    int type = -1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = DlgSugarBinding.inflate(inflater, container, false);
        list.add(binding.tv0);
        list.add(binding.tv1);
        list.add(binding.tv2);
        for (int i = 0; i < list.size(); i++) {
            int j = i;
            list.get(i).setOnClickListener(v -> setType(j));
        }

        binding.btn.setOnClickListener(v -> {
            dismiss(true, type);
        });
        binding.getRoot().setOnClickListener(v -> dismiss());
        return binding.getRoot();
    }

    private void setType(int i) {
        if (type == i) {
            return;
        }
        type = i;
        for (int j = 0; j < list.size(); j++) {
            TextView tv = list.get(j);
            if (j == i) {
                tv.setTextColor(0xff0FB7A2);
                tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.mipmap.green_right, 0);
            } else {
                tv.setTextColor(0xff3a3a3a);
                tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            }
        }
    }
}
